# 十二届2021年复习
import heapq
import math


def path():
    def lcm(a, b):
        return a * b // math.gcd(a, b)

    # 路径
    dist = [float('inf')] * 2022
    dist[0] = dist[1] = 0
    heap = [(0, 1)]  # (到达点1的长度, 当前节点)
    while heap:
        curr_dist, curr = heapq.heappop(heap)
        if curr_dist > dist[curr]:
            continue

        for i in range(1, 22):
            nxt = curr + i
            if nxt > 2021:
                break
            d = dist[curr] + lcm(curr, nxt)
            if d < dist[nxt]:
                dist[nxt] = d
                heapq.heappush(heap, (d, nxt))
    return dist[2021]


print(path())
